<?php
namespace app\english\controller;

use think\Controller;
use app\base\controller\Base;
use think\Validate;
use think\Db;


class Login extends Common
{   
    private $Base;
   
    public function __construct(){
        parent::__construct();
        $this->Base = new Base();

    }

   public function index (){   
        $result = $this->Base->login();
        return json(['msg'=>'登录成功！','code'=>1,'token'=> $result]); 
    }

    //添加用户微信信息

    public function addUser(){
        $result = $this->Base->addUserInfo($this->user);
        if($result){
            return json(['msg'=>'添加成功！','code'=>1]); 
        }
    }

    public function getQuestionList()
    {   
        //添加用户信息
        $this->Base->addWxappUserInfo($this->userId);
        $type = input('type');
        $data['question_list_1'] = Db::name('driving_test')->where('type',$type)->where('subject',1)->select();
        $data['question_list_4'] = Db::name('driving_test')->where('type',$type)->where('subject',4)->select();    
      
        return $data;
    }

    // public function addUserInfo(){
        
    //     $data = $this->request->param();
        
        
    //     if($result || $result == 0){
    //         $this->success("添加成功!");
    //     }else{
    //         $this->success("添加失败!");
    //     }
    // }

    // public function addWxappUserInfo(){
    //     $validate = new Validate([
    //         'encrypted_data' => 'require',
    //         'iv'             => 'require',
    //         'raw_data'       => 'require',
    //         'signature'      => 'require',
    //     ]);

    //     $validate->message([
    //         'encrypted_data.require' => '缺少参数encrypted_data!',
    //         'iv.require'             => '缺少参数iv!',
    //         'raw_data.require'       => '缺少参数raw_data!',
    //         'signature.require'      => '缺少参数signature!',
    //     ]);

    //     $data = $this->request->param();

    //     if (!$validate->check($data)) {
    //         $this->error($validate->getError());
    //     }

    //     $user_info = $this->user;
    //     $wxapp_config_info  = get_wxapp_config();
       
    //     $pc      = new WXBizDataCrypt($wxapp_config_info['appid'],$user_info['session_key']);
       
    //     $errCode = $pc->decryptData($data['encrypted_data'], $data['iv'], $wxUserData);
       
    //     if ($errCode != 0) {
    //         $this->error('操作失败!');
    //     }
        
    //     unset($wxUserData['watermark']);
        
       
        
    //     Db::name('user')->where('id',$this->userId)->update([
    //         'nick_name'   => $wxUserData['nickName'],
    //         'avatar_url'  => $wxUserData['avatarUrl'],
    //         'more'        => json_encode($wxUserData)
    //         ]);
    //     $this->success("添加成功");
    // }

}